package com.offcn.utils;

import javax.servlet.http.Part;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class UploadUtils {
    public static String upload(Part part) {
        //获取文件名
    String filename = part.getSubmittedFileName();
    filename= UUID.randomUUID()+filename;
        //将part中的内容写入文件夹并保存
        String dirpath = "D:/eduSource";
        File file = new File(dirpath);
        if (!file.exists()){
            file.mkdir();
        }
        try {
            part.write(dirpath +"/"+filename);
        } catch (IOException e) {
            e.printStackTrace();
        }return filename;
    }
}
